<template>
  <div class="login-container">
    <!-- 登录 -->
    <div class="login-wrap">
      <div class="login">
        <div class="loginform">
          <div class="current">账 户 登 录</div>
          <div class="content">
            <form>
              <div class="input-text clearFix">
                <span>
                  <i class="icon el-icon-s-custom"></i>
                </span>
                <input type="text" placeholder="请输入用户名" v-model="username" />
              </div>
              <div class="input-text clearFix">
                <span class="pwd">
                  <i class="icon el-icon-s-cooperation"></i>
                </span>
                <input
                  type="text"
                  placeholder="请输入密码"
                  v-model="password"
                />
              </div>
              <!-- <div class="setting clearFix">
                <label class="checkbox inline">
                  <input name="m1" type="checkbox" value="2" checked="" />
                  自动登录
                </label> -->
              <!-- <span class="forget">忘记密码？</span> -->
              <!-- </div> -->
              <button class="btn" @click.prevent="userLogin">
                登&nbsp;&nbsp;录
              </button>
            </form>

            <div class="call clearFix">
              没有账户,去
              <router-link class="register" to="/register">注册</router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    //登录的回调函数
    async userLogin() {
      try {
        //登录成功
        const { username, password } = this;
        username&&password&&(await this.$store.dispatch("userLogin", { username, password }));
        //登录的路由组件：看路由当中是否包含query参数，有：调到query参数指定路由，没有：调到home
         let toPath = this.$route.query.redirect||"/";
         this.$router.push(toPath);
      } catch (error) {
        alert(error.message);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.login-container {
  margin-top: 50px;
  .login-wrap {
    height: 480px;
    .login {
      width: 600px;
      height: 480px;
      margin: 0 auto;
    }

    .loginform {
      width: 500px;
      height: 500px;
      box-sizing: border-box;
      background: #fff;
      margin: 0 auto;
      padding: 20px;
      .current {
        font-size: 30px;
        color: #374a74;
        font-weight: 700;
        background-color: #ececec;
        width: 500px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border: 1px solid #ccc;
      }

      .content {
        width: 500px;
        height: 300px;
        box-sizing: border-box;
        border: 1px solid #ddd;
        border-top: none;
        padding: 18px;

        form {
          margin: 20px auto 0;
          font-size: 12px;
          line-height: 18px;
          > div {
            text-align: center;
          }
          .input-text {
            margin-bottom: 18px;
            margin-left: 65px;
            text-align: center;
            span {
              float: left;
              width: 40px;
              height: 32px;
              line-height: 32px;
              text-align: center;
              border: 1px solid #ccc;
              box-sizing: border-box;
              border-radius: 2px 0 0 2px;
              i{
                font-size:18px;
              }
          
            }

            // .pwd {
            //   background-position: -72px -201px;
            // }

            input {
              width: 300px;
              height: 32px;
              box-sizing: border-box;
              border: 1px solid #ccc;
              border-left: none;
              float: left;
              padding-top: 6px;
              padding-bottom: 6px;
              font-size: 14px;
              line-height: 22px;
              padding-right: 8px;
              padding-left: 8px;
              border-radius: 0 2px 2px 0;
              outline: none;
            }
          }

          .setting {
            label {
              // float: left;
            }

            // .forget {
            //   float: right;
            // }
          }

          .btn {
            background-color: #374a74;
            padding: 6px;
            border-radius: 0;
            font-size: 20px;
            // font-family: 微软雅黑;
            word-spacing: 4px;
            color: #fff;
            width: 100%;
            height: 36px;
            margin-top: 25px;
            outline: none;
          }
        }

        .call {
          margin-top: 30px;
          text-align: center;
          font-size: 14px;
          // ul {
          //   float: left;

          //   li {
          //     float: left;
          //     margin-right: 5px;
          //   }
          // }

          .register {
            text-align: center;
            font-size: 14px;
            line-height: 38px;
            color: #374a74;
            font-weight: bold;
          }

          .register:hover {
            color: #4cb9fc;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
</style>
